Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The errno npm package provides a convenient way to create, manage, and interact with system-level errors in Node.js applications. It allows developers to easily look up error codes and create custom errors that integrate seamlessly with Node.js's error handling mechanisms.
Creating custom errors
This feature allows developers to create custom errors. The code sample demonstrates how to create a new custom error type called 'MyError' and then instantiate an error of this type.
const create = require('errno').create;
const MyError = create('MyError');
const err = new MyError('An error occurred');
Looking up error codes
This feature enables developers to look up error codes by their common names. The code sample shows how to access the properties of the 'errno.code' object to find information about the 'ENOENT' error code.
const errno = require('errno');
console.log(errno.code.ENOENT);
Verror is a package that provides a way to create rich JavaScript errors. It is similar to errno in that it enhances error handling in Node.js applications, but it focuses more on providing a framework for annotating errors than on integrating with system-level errors.
The 'error' package offers a simple way to create custom errors in Node.js, similar to errno's functionality for creating custom errors. However, it does not provide the same level of integration with system-level error codes.
Better libuv/Node.js/io.js error handling & reporting. Available in npm as errno.
Ever find yourself needing more details about Node.js errors? Me too, so node-errno contains the errno mappings direct from libuv so you can use them in your code.
By errno:
require('errno').errno[3]
// → {
// "errno": 3,
// "code": "EACCES",
// "description": "permission denied"
// }
By code:
require('errno').code.ENOTEMPTY
// → {
// "errno": 53,
// "code": "ENOTEMPTY",
// "description": "directory not empty"
// }
Make your errors more descriptive:
var errno = require('errno')
function errmsg(err) {
var str = 'Error: '
// if it's a libuv error then get the description from errno
if (errno.errno[err.errno])
str += errno.errno[err.errno].description
else
str += err.message
// if it's a `fs` error then it'll have a 'path' property
if (err.path)
str += ' [' + err.path + ']'
return str
}
var fs = require('fs')
fs.readFile('thisisnotarealfile.txt', function (err, data) {
if (err)
console.log(errmsg(err))
})
Use as a command line tool:
~ $ errno 53
{
"errno": 53,
"code": "ENOTEMPTY",
"description": "directory not empty"
}
~ $ errno EROFS
{
"errno": 56,
"code": "EROFS",
"description": "read-only file system"
}
~ $ errno foo
No such errno/code: "foo"
Supply no arguments for the full list. Error codes are processed case-insensitive.
You will need to install with npm install errno -g
if you want the errno
command to be available without supplying a full path to the node_modules installation.
Use errno.custom.createError()
to create custom Error
objects to throw around in your Node.js library. Create error hierarchies so instanceof
becomes a useful tool in tracking errors. Call-stack is correctly captured at the time you create an instance of the error object, plus a cause
property will make available the original error object if you pass one in to the constructor.
var create = require('errno').custom.createError
var MyError = create('MyError') // inherits from Error
var SpecificError = create('SpecificError', MyError) // inherits from MyError
var OtherError = create('OtherError', MyError)
// use them!
if (condition) throw new SpecificError('Eeek! Something bad happened')
if (err) return callback(new OtherError(err))
Also available is a errno.custom.FilesystemError
with in-built access to errno properties:
fs.readFile('foo', function (err, data) {
if (err) return callback(new errno.custom.FilesystemError(err))
// do something else
})
The resulting error object passed through the callback will have the following properties: code
, errno
, path
and message
will contain a descriptive human-readable message.
Copyright (c) 2012-2015 Rod Vagg (@rvagg)
Made available under the MIT licence:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
libuv errno details exposed
The npm package errno receives a total of 1,981,498 weekly downloads. As such, errno popularity was classified as popular.
We found that errno demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.